<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>

    let data={
        name:'yjm',
        address: 'wuhan'
    }

//    创建一个监视的实例对象，用于监视data中的属性
    const obs = new Observer(data)
    console.log(obs)
    function Observer(obj) {
    //    汇总对象中所以的属性形成一个数组
        const keys = Object.keys(obj)
    //    遍历
    //     console.log(keys)
        keys.forEach(k=>{
            Object.defineProperty(this,k,{
                get() {
                    return obj[k]
                },
                set(v) {
                  obj[k] = v
                }
            })
        })

    }
</script>
</body>
</html>